/**
 * @desc Api
 * @author liqiang
 * @company fivefire
 * @date 14 Nov 2017
 */

'use strict'

const config = require('../config')
const req = require('./request')
const util = require('./util')
const prefix = config.host //ceshi
// const prefix = config.host + '/wechat/wx/v1' //pro
const requestParam = require('./requestParam')
const wrap = (url, type = 'GET') => (config = {}) => req.request(Object.assign({}, config, {
  method: type,
  url: prefix + url
}))
const wrappost = (url, type = 'GET') => (config = {}) => req.requestPost(Object.assign({}, config, {
  method: type,
  url: prefix + url
}))

const wraposs = (url, type = 'GET') => (config = {}) => req.request(Object.assign({}, config, {
  method: type,
  url: prefixoss + url,
  complete: true
}))
const wraplooposs = (url, type = 'GET') => (config = {}) => req.loopRequest(Object.assign({}, config, {
  method: type,
  url: prefixoss + url,
  complete: true
}))
const wrapaliyun = (url, type = 'GET') => (config = {}) => req.request(Object.assign({}, config, {
  method: type,
  url: url
}))
const wraptool = (url, type = 'GET') => (config = {}) => req.request(Object.assign({}, config, {
  method: type,
  url: url
}))
const api = {
  note: {
    //首页列表
    userNoteList: wrap('/mini/user_note/list_for_page', 'POST'),
    //取消收藏
    cancelCollection: wrappost('/mini/user_note/cancel_collection', 'POST'),
    //取消点赞
    cancelThumbUp: wrappost('/mini/user_note/cancel_thumb_up', 'POST'),
    //笔记详情
    noteDetail: wrap('/mini/user_note/detail'),
    //编辑笔记
    editNote: wrap('/mini/user_note/edit_note', 'POST'),
    //发布笔记
    releaseNote: wrap('/mini/user_note/release_note', 'POST'),
    //搜索
    search: wrap('/mini/user_note/search', 'POST'),
    //点赞
    thumbUp: wrappost('/mini/user_note/thumb_up', 'POST'),
    collection: wrappost('/mini/user_note/collection', 'POST'), //收藏
    recommendList: wrap('/mini/user_note/recommend_list'),
    listMyNotes: wrap('/mini/user_note/list_my_notes', 'POST'), //我的笔记列表
    listMyCollection:wrap('/mini/user_note/list_my_collection')


  },
  comment: {
    //发表评价
    announce: wrap('/user/comment/announce', 'POST'),
    //评价列表
    announceList: wrap('/user/comment/comment_list'),
    //回复
    replayAnnounce: wrap('/user/comment/replay_announce', 'POST'),
    //回复列表
    commentReplyList: wrap('/user/comment/comment_reply_list'),
    commentListThumb: wrap('/user/comment/comment_list_thumb', 'POST'), //评价列表点赞
    commentListUnThumb: wrap('/user/comment/comment_list_un_thumb', 'POST') //评价列表取消点赞
  },
  user: {
    // //解绑手机号
    tool: wraptool(config.host + '/wx/tool/unbindWX?userId=1&userType=3', 'delete'),
    // 微信code码转换成openId
    getToken: wrap('/user/code2token'),
    // 微信小程序手机绑定，即登录
    login: wrap('/user/thrid_login', 'POST'),
    // 获取短信验证码 10: 短信验证
    sms: wrap('/user/sms'),
    // 获取校验码图片
    verifyCode: wrap('/user/verify_code'),
    detail: wrap('/user/detail'),
    update: wrap('/user/update', 'POST'),
    authentication: wrap('/user/authentication', 'POST')
  },
  lable: {
    lableList: wrap('/mini/system_label/list')
  },
  oss: {
    createVideo: wraposs('/create'),
    getPlayUrl: wraplooposs('/play_url')
  },
  aliyun: {
    getVideoUrl: wrapaliyun('http://vod.cn-shanghai.aliyuncs.com')
  },
  uploadMedia: {
    uploadImg: prefix + '/mini/oss/upload_img?businessType=3',
    uploadVideos: prefix + '/mini/oss/upload_video?businessType=3'
  }
}

module.exports = api

